﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;
using System.ComponentModel;

using TravelSite.Entities;
using TravelSite.DAL;
using TravelSite.DAL.Repositories;
using Travel.Api.Code;

namespace Travel.Api.Code
{
    public class Utils
    {
        public static bool CheckPin(string pin)
        {
            using (var repo = RepositoryFactory.ResolveRepository<ApiContactRepository>())
            {
                Contact cnt = repo.FindByPin(pin);
                return (cnt != null);
            }
        }

        public static Contact GetContact(string pin)
        {
            using (var repo = RepositoryFactory.ResolveRepository<ApiContactRepository>())
            {
                Contact cnt = repo.FindByPin(pin);
                return cnt;
            }
        }
        
        public static string GetEnumDescription(Enum value)
        {
            FieldInfo fi = value.GetType().GetField(value.ToString());

            DescriptionAttribute[] attributes =
                (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);

            if (attributes != null && attributes.Length > 0)
                return attributes[0].Description;
            else
                return value.ToString();
        }


    }
}